// pages/King/King.js
//import {get,post} from '../../request/index'
const {
  get,
  post
} = require('../../request/index')
const util = require('../../utils/util')

const {getMonth} = require('../../utils/time')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    prolist: wx.getStorageSync('prolist') == '' ? wx.getStorageSync('prolist') : JSON.parse(wx.getStorageSync('prolist')),
    dwnum: null,
    dwsum: null,
    ywnum: null,
    ywsum: null,
    wnum:null,
    wsum:null,
    ynum:null,
    ysum:null,
    time: '',
    time2: util.formatDate(new Date())
  },
  // 当前挖掘机产量
  mapCalculatea() {

    let {
      prolist
    } = this.data
    post(`/app/mapCalculate/getAuto?currentPage=1&pageSize=100`, {
      type: 1,
      mineId: prolist.mineId

    }).then(res => {
      console.log(res);

      this.setData({
        dwnum: res.data.list[0].diggerCarSum,
        dwsum: res.data.list[0].diggerMoney
      })

    })
  },
  // 当前运输车产量
  mapCalculateb() {

    let {
      prolist
    } = this.data
    post(`/app/mapCalculate/getAuto?currentPage=1&pageSize=100`, {
      type: 2,
      mineId: prolist.mineId

    }).then(res => {
      console.log(res);

      this.setData({
        ywnum: res.data.list[0].diggerCarSum,
        ywsum: res.data.list[0].diggerMoney
      })

    })
  },

  // 当月挖掘机
  mapyieldGetcarsuba() {
    let {
      prolist
    } = this.data
    let date = new Date(),
      y = date.getFullYear(),
      m = date.getMonth();
   
    let firstDay = new Date(y, m, 1);
    let lastDay = new Date(y, m + 1, 0);
    let a = `${getMonth(firstDay)} 00:00:00`;
    let b = `${getMonth(lastDay)} 23:59:00`

    post(`/app/mapyield/getcarsub`, {
      importTime: a, 
      outTime: b,
      mineId: prolist.mineId,
    }).then(res=>{
      this.setData({
        wnum:res.data.num,  
        wsum:res.data.sum
      })
     
    })

  },
  // 当月运输车
  mapyieldGetcarsubb() {
    let {
      prolist
    } = this.data
    let date = new Date(),
      y = date.getFullYear(),
      m = date.getMonth();
    let firstDay = new Date(y, m, 1);
    let lastDay = new Date(y, m + 1, 0);

    post(`/app/mapyield/transport`, {
      importTime: `${getMonth(firstDay)} 00:00:00`,
      outTime: `${getMonth(lastDay)} 23:59:00`,
      mineId: prolist.mineId,
    }).then(res=>{
      this.setData({
        ynum:res.data.num,
        ysum:res.data.sum
      })
     
    })},



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad (options){ 
    this.mapCalculatea()
    this.mapCalculateb()
    this.mapyieldGetcarsuba()
    this.mapyieldGetcarsubb()
    const that = this
    setInterval(function () {
      const time = util.formatTime(new Date())
      that.setData({
        time: time
      })
    }, 1000)


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})